package com.study.controller;

import cn.hutool.json.JSONUtil;
import com.study.common.result.Result;
import com.study.common.util.ResultUtil;
import com.study.entity.SysUser;
import com.study.service.api.hx.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("user")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 登录
     * @param userName
     * @param passWord
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/login")
    public Result login(@RequestParam("userName") String userName, @RequestParam("passWord") String passWord) throws Exception {
        return ResultUtil.success("2222");
    }

    /**
     * 登录
     * @param chrId
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/findUserById")
    public Result findUserById(@RequestParam("chrId") String chrId) throws Exception {
        return ResultUtil.success(sysUserService.findUserById(chrId));
    }

    /**
     * 修改用户
     * @param sysUser
     * @return
     */
    @PostMapping(value = "/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        if(sysUserService.updateSysUser(sysUser)>0){
            return ResultUtil.success();
        }else {
            return ResultUtil.error("修改失败，请检查密码是否正确");
        }
    }

    /**
     * 模拟接口测试
     * @author hw
     * @date 2022/6/16 10:35:53
     * @return java.util.Map
     */
    @PostMapping(value = "/getPerson")
    public Map getPerson(){
        String person = "{\"result\":[{\"hh\":\"001548959\",\"dqm\":\"江西省吉安市\",\"xz\":\"金滩镇午冈村老居自然村51号\",\"zzrqchar\":\"\",\"cjsy\":\"\",\"gmsfhm\":\"362422199810034312\",\"zt_dic\":\"有效\",\"bdrq\":\"1221580800\",\"hkszd\":\"江西省吉水县金滩镇午冈村老居自然村\",\"xczjhm\":\"\",\"xm\":\"黄武\",\"hlx\":\"集体户\",\"hjdz_cxfldm_dic\":\"镇乡结合区(城镇)\",\"zt\":0,\"ssssxq\":\"江西省吉水县\",\"qwd\":\"\"}],\"success\":true}";

        Map serviceDescript = new HashMap(16);
        serviceDescript.put("header", new HashMap<>(16));
        serviceDescript.put("data",person);

        Map result = new HashMap(16);
        result.put("code","SS1000");
        result.put("invokTime","11323");
        result.put("message","服务请求成功");
        result.put("senderID","C10-00000147");
        result.put("serviceDescript",serviceDescript);

        System.out.println(JSONUtil.toJsonStr(result));
        return result;
    }

    @PostMapping(value = "/getCar")
    public Map getCar(){
        String person ="{\"result\":[{\"clpp1\":\"五菱宏光\",\"hphm\":\"hw1234\",\"cllx\":\"四轮\",\"ccdjrq\":\"1221580800\",\"syxz\":\"私用\",\"yxqz\":\"1221580800\",\"hpqysj\":\"1221580800\",\"zt\":\"有效\",\"pl\":\"111\",\"syr\":\"黄武\",\"sfzmhm\":\"362422199810034312\"}],\"success\":true}";
        Map serviceDescript = new HashMap(16);
        serviceDescript.put("header", new HashMap<>(16));
        serviceDescript.put("data",person);

        Map result = new HashMap(16);
        result.put("code","SS1000");
        result.put("invokTime","11323");
        result.put("message","服务请求成功");
        result.put("senderID","C10-00000147");
        result.put("serviceDescript",serviceDescript);

        System.out.println(JSONUtil.toJsonStr(result));
        return result;
    }
}